package com.ruoyi.oss.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.oss.cloud.CloudStorageConfig;
import com.ruoyi.oss.service.IOssService;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;

@Service
public class OssServiceImpl implements IOssService {
	
	@Autowired
	private ISysConfigService sysConfigService;
	
	private final static String KEY = Constants.CLOUD_STORAGE_CONFIG_KEY;

	@Override
	public <T> T getValueObject(Class<T> clazz) {
		String config = sysConfigService.getConfigValue(KEY);
	    return JSONObject.parseObject(config, clazz);
	}

	@Override
	public void saveConfig(CloudStorageConfig config) {
		SysConfig sysConfig = new SysConfig();
		sysConfig.setConfigKey(KEY);
		sysConfig.setConfigValue(JSON.toJSONString(config));
		sysConfigService.saveConfig(sysConfig);
	}

}
